package com.xiaoluo.a17_countdown;

import android.os.CountDownTimer;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;


public class TimeCount extends CountDownTimer {
    private static final String TAG = "TimeCount";

    Button mTargetBtn;
    TextView mTargetText;

    public TimeCount(long millisInFuture, long countDownInterval, TextView targetView) {
        // 参数依次为总时长,和计时的时间间隔
        super(millisInFuture, countDownInterval);

        if (targetView instanceof TextView) {
            mTargetText = (TextView) targetView;
        }

    }

    @Override
    public void onFinish() {
        // 计时完毕时触发
        Log.i(TAG, "onFinish: ");
    }

    @Override
    public void onTick(long millisUntilFinished) {
        // 计时过程显示
        if (mTargetText != null) {
            mTargetText.setText(millisUntilFinished / 1000 + " s");
            mTargetText.setClickable(false);
        }
    }

}